program AddResnum
implicit none

character(len=79)ARGUMENT,INPUTFILE,PDB
integer i,j,k,ios,c1(50000),c2(50000),c3(50000),c4(50000),c5(50000),connum1,connum2,nargs
real d1(50000),d2(50000)
character(len=20),dimension(20) :: col

nargs=iargc()
  if(nargs==2)then 
     call getarg(1,INPUTFILE)
     call getarg(2,PDB)
  else
  write(*,*) " "
  write(*,*) "Wrong Input!"
  write(*,*) "INPUTFILE  PDBFILE!"
  write(*,*) " "
  goto 100
  endif

ios=0
i=0
open(1,file=INPUTFILE,status="old")
do while(.true.)
 read(1,"(A)",iostat=ios)ARGUMENT
 if(ios/=0)exit
  i=i+1
 read(ARGUMENT,*) (col(k),k=1,3)
 read(col(1),"(I4)") c1(i)
 read(col(2),"(I4)") c2(i)
 read(col(3),"(F5.3)") d1(i)
enddo
close(1)
connum1=i
  write(*,*) connum1

ios=0
i=0
open(2,file=PDB,status="old")
do while(.true.)
 read(2,"(A)",iostat=ios)ARGUMENT
 if(ios/=0)exit
 i=i+1
 read(ARGUMENT(24:26),"(I3)") c3(i)
enddo
close(2)

open(3,file="native.dat",status="replace")
do i=1,connum1
  write(3,"(1X,I4,3X,I4,3X,F5.3,3X,I4,3X,I4,1X,I)") c1(i),c2(i),d1(i),c3(c1(i)),c3(c2(i)),1
enddo
close(3)


ios=0
i=0
open(10,file="nonnative.list",status="old")
do while(.true.)
 read(10,"(A)",iostat=ios)ARGUMENT
 if(ios/=0)exit
  i=i+1
 read(ARGUMENT,*) (col(k),k=1,3)
 read(col(1),"(I4)") c4(i)
 read(col(2),"(I4)") c5(i)
 read(col(3),"(F5.3)") d2(i)
! read(ARGUMENT(3:5),"(I3)") c4(i)
! read(ARGUMENT(11:13),"(I3)") c5(i)
! read(ARGUMENT(19:23),"(F5.3)") d2(i)
enddo
close(10)
connum2=i
  write(*,*) connum2


open(30,file="nonnative.dat",status="replace")
do i=1,connum2
  write(30,"(1X,I4,3X,I4,3X,F5.3,3X,I4,3X,I4)") c4(i),c5(i),d2(i),c3(c4(i)),c3(c5(i))
enddo
close(30)
100 end program
